<style lang="less">
@import '../../../styles/common.less';
</style>

<template>
    <Card>
        <Form action="" method="get" name="exportData" id="exportData" enctype="multipart/form-data">
            <Card>
                <header>
                    <span>申请日期(起):</span>
                    <DatePicker type="date" placeholder="申请日期(起)" v-model="listQueryCondition.applyBeginDate" style="width: 150px" name="applyBeginDate" value="yyyy-MM-dd"></DatePicker>
                    <span> -</span>
                    <span>申请日期(止):</span>
                    <DatePicker type="date" placeholder="申请日期(止)" v-model="listQueryCondition.applyEndDate" style="width: 150px" name="applyEndDate" value="yyyy-MM-dd"></DatePicker>
                    <span style="width: 200px;margin-left: 25px;">客户姓名:</span>
                    <Input v-model="listQueryCondition.custName" placeholder="客户姓名" style="width: 150px" name="custName" />
                    <span style="width: 200px;margin-left: 25px;">产品:</span>
                    <Select v-model="listQueryCondition.productCode" style="width:150px" placeholder="产品" name="productCode">
                        <Option v-for="item in productList" :value="item.productType" :key="item.productType">{{item.productTypeName}}</Option>
                    </Select>
                    <span style="width: 200px;margin-left: 25px;">资金方:</span>
                    <Select v-model="listQueryCondition.fundSourceCode" style="width:150px" placeholder="资金方" name="fundSourceCode">
                        <Option v-for="item in fundList" :value="item.fundCode" :key="item.fundCode">{{item.fundName}}</Option>
                    </Select>
                    <Button type="primary" @click="listQuery" style="margin-left: 25px;">查询</Button>
                </header>
            </Card>
            <Card>
                <div>
                    <Table border ref="selection" :columns="applyingColumns" :data="applyingData" style="width: 100%;" @on-selection-change="handleRowChange"></Table>
                    <Table border :columns="statisticsColumns" :data="statisticsData" style="width: 100%;" :show-header=false></Table>
                </div>

                <div class="audit-div">
                    <Button type="primary" @click="pass" style="margin:0px 0px 0px 20px;width: 90px" >通过</Button>

                    <Button type="primary" @click="refuse" style="margin-left: 15px;margin:0px 0px 0px 20px;width: 90px">拒绝</Button>

                    <Button type="primary" @click="cancle" style="margin-left: 15px;">取消放款</Button>

                    <Button type="primary" @click="handLoan" style="margin-left: 15px;">手动放款</Button>
                </div>

                <div class="export-div">
                    <Button type="primary" @click="exportCurrent">导出当前页面</Button>

                    <Button type="primary" @click="exportAll" style="margin-left: 20px;margin:0px 0px 0px 20px;width: 110px">导出全部</Button>
                </div>

                <div class="bottom-page-div">
                    <Page :total="listQueryCondition.total" :current="listQueryCondition.pageNum" :page-size="listQueryCondition.pageSize" size="small" show-elevator show-sizer show-total @on-change="pageChange" @on-page-size-change="sizeChange"></Page>
                </div>
            </Card>
            <input type="hidden" name="pageNum" id="pageNum" value="" />
            <input type="hidden" name="pageSize" id="pageSize" value="" />
            <input type="hidden" name="exportOperation" id="exportOperation" value="" />
        </Form>
    </Card>
</template>

<script type="text/javascript">
</script>
<script>
import expandRow from './table-expand.vue';
export default {
    name: 'mutative-router',
    components: { expandRow },
    data () {
        return {
            loanIds:'',
            i:0,
            operationStatus:'',//1 通过  2 拒绝 3取消放款
            listQueryCondition:{
                productCode:'',
                fundSourceCode:'',
                custName:'',
                applyBeginDate:'',
                applyEndDate:'',
                pageNum:1,
                pageSize:10,
                total:0,
                exportOperation:''
            },
            productList: [],
            fundList: [],
            applyingColumns: [
             {
                    type: 'selection',
                    width: 150,
                    align: 'center'
                },
                {
                    title: '姓名',
                    key: 'custName',
                    align: 'center'
                },
                {
                    title: '身份证号',
                    key: 'custCardNo',
                    align: 'center'
                },
                {
                    title: '银行卡号',
                    key: 'receiveAcctNo',
                    align: 'center'
                },
                {
                    title: '开户行',
                    key: 'receiveBankName',
                    align: 'center'
                },
                {
                    title: '产品',
                    key: 'productTypeName',
                    align: 'center'
                },
                {
                    title: '贷款金额',
                    key: 'principalAmtAct',
                    align: 'center'
                },
                {
                    title: '到手金额',
                    key: 'aviAmount',
                    align: 'center'
                },
                {
                    title: '咨询费',
                    key: 'consultingFee',
                    align: 'center'
                },
                {
                    title: '期限',
                    key: 'terms',
                    align: 'center'
                },
                {
                    title: '申请时间',
                    key: 'loanTime',
                    align: 'center',
                    render: (h, params) => {
                        var vm = this;
                        return h('div', [
                            h('span', vm.$util.loanModularFormatTime(params.row.loanTime))
                        ]);
                    }
                },
                {
                    title: '申请人',
                    key: 'createdBy',
                    align: 'center'
                },
                {
                    title: '资金方',
                    key: 'fundName',
                    align: 'center'
                }
            ],

            statisticsColumns: [
             {
                    width: 150,
                    key: 'selection',
                    align: 'center'
                },
                {
                    key: 'custName',
                    align: 'center'
                },
                {
                    key: 'custCardNo',
                    align: 'center'
                },
                {
                    key: 'receiveAcctNo',
                    align: 'center'
                },
                {
                    key: 'receiveBankName',
                    align: 'center'
                },
                {
                    key: 'productName',
                    align: 'center'
                },
                {
                    key: 'principalAmtAct',
                    align: 'center'
                },
                {
                    key: 'aviAmount',
                    align: 'center'
                },
                {
                    key: 'consultingFee',
                    align: 'center'
                },
                {
                    key: 'terms',
                    align: 'center'
                },
                {
                    key: 'loanTime',
                    align: 'center'
                },
                {
                    title: '申请人',
                    align: 'center'
                },
                {
                    title: '资金方',
                    align: 'center'
                }
            ],
            applyingData: [],
            statisticsData: [{"selection":"当前页合计","principalAmtAct":"0.00","aviAmount":"0.00","consultingFee":"0.00"}]
        };
    },
    computed: {
        avatorImage () {
            return localStorage.avatorImgPath;
        }
    },
    created(){
      //初始化当前页面请求对象实例
      this.$ajax = this.$util.ajax();
      this.screenConditon();
    },
    methods:{
        screenConditon(){
        var vm = this;
            this.$ajax.post(this.$appContext.marvels_core_approve+'approve/loanList/service/listScreenCondition').then( re => {
                var data = re.data;
                var code = data.code;
                var message = data.message;
                if(code != 'success') {
                    this.$Message.warning(message);
                    return;
                }
                vm.fundList.push({fundCode:'',fundName:'请选择'});
                var fundLength=0;
                for(;fundLength<data.data.fundList.length;fundLength++){
                 vm.fundList.push(data.data.fundList[fundLength]);
                }
                vm.productList.push({productType:'',productTypeName:'请选择'});
                var productLength=0;
                for(;productLength<data.data.productList.length;productLength++){
                 vm.productList.push(data.data.productList[productLength]);
                }
            } ).catch( er => {

            } );
        },
        handleRowChange(selection){
        var vm = this;
        this.loanIds='';
        this.i=0;
        for(;this.i<selection.length;this.i=this.i+1){
                this.loanIds=selection[this.i].loanId+','+this.loanIds;
            }
            this.innerListInfoData=selection;
        },
        pass(){
            var vm = this;
            vm.optationStatus='1';
            vm.loanPass();
        },
        refuse(){
            var vm = this;
            vm.optationStatus='2';
            vm.loanRefuse();
        },
        cancle(){
            var vm = this;
            vm.optationStatus='3';
            vm.loanCancle();
        },
        handLoan(){
            var vm = this;
            vm.optationStatus='4';
            vm.loanHandle();
        },
        loanHandle(){
            var vm = this;
            if(vm.loanIds===''){
                this.$Message.warning("请至少选择一项进行操作");
                return ;
            }
            this.$Modal.confirm({

              content: '手动放款为我方生成还款计划,确定继续?',

              okText: '确定',

              cancelText: '取消',
              onOk: () => {
                var data={"loanIds":this.loanIds};
                this.$ajax.post(this.$appContext.marvels_core_financial+'financial/loan/loanAudit/service/handlePay',data).then( re => {
                var data = re.data;
                // console.info(data);
                var code = data.code;
                var message = data.message;
                if(code != 'success') {
                    this.$Message.warning(message);
                    return;
                }else{
                    this.$Message.info("处理成功")
                }
                vm.listQuery();
                } ).catch( er => {

                } );
              }
            })

        },
        loanPass(){
            var vm = this;
            if(vm.loanIds===''){
                this.$Message.warning("请至少选择一项进行操作");
                return ;
            }
            var data={"loanIds":this.loanIds};
            this.$ajax.post(this.$appContext.marvels_core_financial+'financial/loan/loanAudit/service/loanAuditPass',data).then( re => {
                var data = re.data;
                // console.info(data);
                var code = data.code;
                var message = data.message;
                this.$Message.warning(message);
                if(code != 'success') {
                    return;
                }
                vm.listQuery();
            } ).catch( er => {

            } );
        },
        loanRefuse(){
            var vm = this;
            if(vm.loanIds===''){
                this.$Message.warning("请至少选择一项进行操作");
                return ;
            }
            var data={"loanIds":this.loanIds};
            this.$ajax.post(this.$appContext.marvels_core_financial+'financial/loan/loanAudit/service/loanAuditRefuse',data).then( re => {
                var data = re.data;
                // console.info(data);
                var code = data.code;
                var message = data.message;
                if(code != 'success') {
                    this.$Message.warning(message);
                    return;
                }
                vm.listQuery();
            } ).catch( er => {

            } );
        },
        loanCancle(){
            var vm = this;
            if(vm.loanIds===''){
                this.$Message.warning("请至少选择一项进行操作");
                return ;
            }
            var data={"loanIds":this.loanIds};
            this.$ajax.post(this.$appContext.marvels_core_financial+'financial/loan/loanAudit/service/loanAuditCancle',data).then( re => {
                var data = re.data;
                // console.info(data);
                var code = data.code;
                var message = data.message;
                if(code != 'success') {
                    this.$Message.warning(message);
                    return;
                }
                vm.listQuery();
            } ).catch( er => {

            } );
        },
        listQuery(){
            var vm=this;
            this.$ajax.post(this.$appContext.marvels_core_financial+'financial/loan/loanAudit/service/auditList',this.listQueryCondition).then( re => {
                var data = re.data;
                var code = data.code;
                var message = data.message;
                if(code != 'success') {
                    this.$Message.warning(message);
                    return;
                }
                vm.applyingData =data.data.applyingList;
                vm.listQueryCondition.total = data.data.total;
                vm.statisticsData=data.data.statisticsList;
            } ).catch( er => {

            } );
        },
        downLoad(){
            var vm = this;
            document.getElementById("exportData").action=this.$appContext.marvels_core_financial+'financial/loan/loanAudit/service/downLoad';
            document.getElementById("pageNum").value=this.listQueryCondition.pageNum;
            document.getElementById("pageSize").value=this.listQueryCondition.pageSize;
            document.getElementById("exportOperation").value=this.listQueryCondition.exportOperation;
          document.getElementById("exportData").submit();
        },

        pageChange:function(pageNum){
            var vm = this;
            vm.listQueryCondition.pageNum = pageNum;
            vm.listQuery();
        },
        sizeChange:function(pageLength){
            var vm = this;
            vm.listQueryCondition.pageSize=pageLength;
            vm.listQuery();
         },
         exportCurrent(){
             var vm=this;
             if(vm.applyingData===null || vm.applyingData.length<1){
                 this.$Message.warning("当前页无可下载数据");
                 return ;
             }
             vm.listQueryCondition.exportOperation='1';
             vm.downLoad();
         },
         exportAll(){
            var vm=this;
            vm.listQueryCondition.exportOperation='2';
            vm.downLoad();
        }

    }
};
</script>

<style>
.i-icon {
  float: left;
  margin-left: 20px;
}
.top-div {
  margin-top: 30px;
}

.left-div {
  width: 150px;
  float: left;
}

.common-div {
  width: 150px;
  float: left;
  margin-left: 13px;
}

.i-icon {
  float: left;
  margin-left: 20px;
}

.query-button {
  width: 150px;
  float: left;
  text-align: center;
}

.pass-button {
  margin-left: 13px;
}

.export-div {
  margin-top: 191px;
  text-align: center;
}
.bottom-page-div {
  margin-top: 120px;
  text-align: center;
}
.refuse-button {
  margin-left: 13px;
  background-color: rgba(25, 190, 107, 0.68);
}
.cancle-loan-button {
  margin-left: 13px;
  background-color: rgba(255, 153, 0, 0.81);
}
.hand-loan-button {
  margin-left: 13px;
  background-color: red;
}
.audit-div {
  margin-top: 100px;
  text-align: center;
  float: left;
}
</style>
